﻿using KuiHuaBaoDian.Services.Guide;
using UnityEditor;
using UnityEngine;

namespace KuiHuaBaoDian.GuideGraph.Editor {

    static class GuideGraphSettingsProvider {

        private static SerializedObject m_Object;
        private static SerializedProperty m_AssemblyDefinitionAssetsProperty;
        private static SerializedProperty m_EditorAssemblyDefinitionAssetsProperty;

        [SettingsProvider]
        public static SettingsProvider 新手引导() {
            return new SettingsProvider($"Project/{nameof(新手引导)}", SettingsScope.Project) {
                label = $"{nameof(新手引导)}",
                activateHandler = (searchContext, rootElement) => {
                    var setting = GuideSetting.Instance;
                    m_Object = new SerializedObject(setting);
                    m_AssemblyDefinitionAssetsProperty = m_Object.FindProperty(nameof(GuideSetting.AssemblyDefinitionAssets));
                    m_EditorAssemblyDefinitionAssetsProperty = m_Object.FindProperty(nameof(GuideSetting.EditorAssemblyDefinitionAssets));
                },
                guiHandler = searchContext => {
                    if (m_Object != null) {
                        EditorGUILayout.PropertyField(m_AssemblyDefinitionAssetsProperty, new GUIContent("目标程序集"));
                        EditorGUILayout.PropertyField(m_EditorAssemblyDefinitionAssetsProperty, new GUIContent("编辑器扩展程序集"));
                        m_Object.ApplyModifiedPropertiesWithoutUndo();
                    }
                },
                deactivateHandler = () => {
                    m_Object = null;
                    m_AssemblyDefinitionAssetsProperty = null;
                    m_EditorAssemblyDefinitionAssetsProperty = null;
                }
            };
        }
    }
}
